
#ifndef   __SIMPHONY_COMMUNICATION_MODULE
#define   __SIMPHONY_COMMUNICATION_MODULE

#define   SMS_PACKET_RECEIVE_TIMEOUT		40 //Sec

#define   SMS_COMMANDS_QUEUE_MAX				15
//#define   COMMANDS_SET_MAX						8
#define   COMMAND_HEADER_SIZE					10

#define   OFFSET_PASSWORD						2
#define   OFFSET_MESSAGE_ID					6
#define   OFFSET_MESSAGE_NUMBER				8
#define   OFFSET_MESSAGES_COUNT				10	
#define   OFFSET_COMMAND_NAME					12	
#define   OFFSET_COMMAND_PARAMETERS			14	

/* Sys.(internal) commands from application */
#define   SYS_APPLICATION				240
#define   SYS_COMMAND_BUFFER_SIZE	64
extern unsigned char Sys_Command_Buffer[SYS_COMMAND_BUFFER_SIZE];
extern near bit SYS_COMMAND, EP_ACCESSES_OPEN;

extern void (*Special)(void);

void Cmd_Return ( void );

/* Example: ##A1F9MI0203CM, where ## - Command Token, A1F9 - (Hex)Password, MI - Message_ID,
	02 - Message Number,
	03 - Message Count, 
	CM - Command*/

//##88f8WJ0202SP0202F401!00005$

/* Command Handlers Errors */
#define   COMMAND_HANDLER_ERROR__INPUT_DATA		10

typedef struct 
{
		unsigned char Password[4];
		unsigned int Message_ID;
		unsigned char Message_Number;
		unsigned char Messages_Count;
		
}COMMAND_HEADER;


typedef union 
{	
		unsigned long Data[4];
		
		struct 
		{
				unsigned long MessageFlags_1;
				unsigned long MessageFlags_2;

				unsigned int Message_ID;
				unsigned char Messages_Count;
				
				unsigned NEED_ACK 						: 	1;
				unsigned PREFIXES_DELETE				:	1;
				unsigned IMSI_RANGE_DELETE				:	1;
				unsigned NMS_PHONE_LIST_DELETE		:	1;
				
				unsigned b4			  				 		:	1;
				unsigned b5			  				 		:	1;
				unsigned b6			  				 		:	1;
				unsigned b7			  				 		:	1;
				
				unsigned int Last_Message_ID;
				unsigned int Timeout; /* Min */
				
		}Field;

}SMS_PACKET_RECEIVE;



/* typedef union  */
/* { */
/* 		unsigned char Data[]; */
/* 		struct  */
/* 		{ */
/* 				unsigned char Password[4]; */
/* 				unsigned int Message_ID; */
/* 				unsigned char SMS_Count; */
/* 		}Field; */

/* }COMMAND_HEADER; */



//PREFIX Prefixes[5];


/* typedef union  */
/* { */
/* 		unsigned char Data[161]; */
/* 		struct  */
/* 		{ */
/* 				COMMAND_HEADER CommandHeader; */
/* 				union */
/* 				{ */
/* 						unsigned char ParametersData[]; */
/* 						//PREFIX Prefixes[5]; */
						
/* 				}Parameter; */
				
/* 		}Field; */
		
/* }COMMAND_LINE; */


/* typedef union  */
/* { */
/* 		unsigned char Data[161 - OFFSET_COMMAND_NAME];   */
/* 		struct  */
/* 		{ */
/* 				unsigned char CommandName[2]; */
/* 				unsigned char Parameters[]; */
							
/* 		}Field; */
		
/* }COMMAND_LINE; */


typedef struct
{
		const unsigned char* CommandName; 
		void ( *CommandHandler ) (void); 
		
}COMMAND_SET;



//extern void (*Execute_Module) (void);
 
void Command_Init ( void );

//extern COMMAND_SET CommandsSet[COMMANDS_SET_MAX];

extern bit DO_RESET;

extern unsigned char Login_Of_UserName[20]; /* phone number of user that login to the System (see LG command)*/

extern unsigned long RC_PressedKey;	  /* Remote Control */

extern unsigned char SMS_Commands[SMS_COMMANDS_QUEUE_MAX];	/* SMS message numbers of comamnds (commands queue) */
extern unsigned char pSMS_Commands;

//extern unsigned char Message_ID[3];
extern unsigned int  Message_ID;	  /* Random value - use as label for Set Date and Time */
extern unsigned char SMS_Packet_Counter;

extern SMS_PACKET_RECEIVE SMS_Packet_Receive;

//extern unsigned char CommandPassword[4];

//unsigned char CommandPassword_Generator( void );
void AddCommand( unsigned char CommandNumber );
//void Command_Translator( void );
void Command_Processor( void );
//void SMS_CreateHeader( unsigned char*  );

void SMS_CreateHeader( unsigned char* Message, unsigned char* DestinationPhone );

unsigned char SendStatus( unsigned char* DestinationPhone );

void Send_Event( void );

int ExeSysCommand (unsigned char *Command );
unsigned char cmd_add_cmd ( unsigned char* ComLine );

#endif



